package com.zrrd.jt_admin.common.filter;

import org.apache.commons.lang3.StringUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author ZhangYK
 * @version 8.0
 * @title MyFilter
 * @description
 * @create 2024/6/28 19:09
 */
@WebFilter(urlPatterns = "/admin/*")
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        //登录操作放行
        if (request.getRequestURI().startsWith("/admin/login")) {
            filterChain.doFilter(servletRequest, servletResponse);
        }
        String token = request.getHeader("token");
        System.out.println(token);
        //通过判断token
        if (StringUtils.isBlank(token)){
            System.out.println("拦截成功！");
            return;
        }
        System.out.println("拦截失败");
        filterChain.doFilter(request, servletResponse);
    }
}
